package com.robot.mvvm.ui.work

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import com.alibaba.android.arouter.facade.annotation.Route
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import com.robot.mvvm.BR
import com.robot.mvvm.R
import com.robot.mvvm.databinding.AppActivityRepairWorkOrderDetailBinding
import com.robot.mvvm.vm.work.RepairWorkOrderDetailViewModel

@Route(path = AppConstants.Router.Main.A_REPAIR_WORK_ORDER_DETAIL)
class RepairWorkOrderDetailActivity :
    GLBaseActivity<AppActivityRepairWorkOrderDetailBinding, RepairWorkOrderDetailViewModel>() {

    private var mTitles = mutableListOf<String>()

    private var fragmentList = mutableListOf<Fragment>()

    var questionId = ""
    override fun initContentView(savedInstanceState: Bundle?): Int =
        R.layout.app_activity_repair_work_order_detail

    override fun initVariableId(): Int = BR.viewModel

    override fun initComponents() {
        addSingleTitleBar(getString(R.string.app_tips_64))
        initViewPager()
    }

    override fun initParam() {
        super.initParam()
        questionId = intent.getStringExtra(AppConstants.BundleKey.QUESTION_ID) ?: ""
    }

    fun initViewPager() {
        mTitles =
            mutableListOf<String>(
                getString(R.string.app_tips_65),
                getString(R.string.app_tips_66)
            )
        fragmentList.add(RepairWorkOrderInfoFragment.newInstance(questionId))
        fragmentList.add(RepairWorkOrderScheduleFragment.newInstance(questionId))

        binding.mViewPager.adapter = object : FragmentStatePagerAdapter(supportFragmentManager) {
            override fun getItem(position: Int): Fragment = fragmentList[position]
            override fun getCount(): Int = fragmentList.size
        }
        binding.mViewPager.offscreenPageLimit = fragmentList.size
        binding.tabLayout.setViewPager(binding.mViewPager, mTitles.toTypedArray())
        binding.tabLayout.currentTab = 0

        binding.mViewPager.setOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {

            }

            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {

            }

            override fun onPageSelected(position: Int) {

            }

        })
    }
}